import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockingQUeue1 {
    public static BlockingQueue<Integer>queue=new LinkedBlockingQueue<>();
    public static void main(String[] args) throws InterruptedException {
        Thread customer=new Thread(()->{
           while (true){
               try {
                   int vaule=queue.take();
                   System.out.println(Thread.currentThread().getName()+"消费元素："+vaule);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        },"customer");
   customer.start();

   Thread producer=new Thread(()->{
       Random random=new Random();
      while(true) {

          try {
              int vaule=random.nextInt(1000);
              System.out.println(Thread.currentThread().getName()+"生产元素："+vaule);
              queue.put(vaule);
          } catch (InterruptedException e) {
              throw new RuntimeException(e);
          }
      }
   },"producer");
//customer.start();
producer.start();
Thread.sleep(10000);
    }
}
